package com.lancoo.ccas53.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lancoo.ccas53.arrangecourse.ArrangeCourseService;
import com.lancoo.ccas53.entity.Campus;
import com.lancoo.ccas53.entity.*;
import com.lancoo.ccas53.exception.BizException;
import com.lancoo.ccas53.mapper.*;
import com.lancoo.ccas53.pojo.common.PageInfo;
import com.lancoo.ccas53.pojo.constant.GlobalConstant;
import com.lancoo.ccas53.pojo.constant.ScheduleState;
import com.lancoo.ccas53.pojo.dto.*;
import com.lancoo.ccas53.pojo.response.basicPlatform.BaseGrade;
import com.lancoo.ccas53.pojo.vo.*;
import com.lancoo.ccas53.service.*;
import com.lancoo.ccas53.util.BatchInsert;
import com.lancoo.ccas53.util.PagingUtil;
import com.lancoo.ccas53.util.SplitTeacherTeachingClass;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.time.LocalDateTime;
import java.util.*;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
 * <p>
 * 教学班 服务实现类
 * </p>
 *
 * @author quin.song
 * @since 2024-05-20
 */
@Slf4j
@Service
public class TeachingClassServiceImpl extends ServiceImpl<TeachingClassMapper, TeachingClass> implements TeachingClassService {

    @Resource
    private TeachingClassMapper teachingClassMapper;
    @Resource
    private TeachingClassStudentMapper teachingClassStudentMapper;
    @Resource
    private TeachingClassTeacherMapper teachingClassTeacherMapper;
    @Resource
    private TeachingClassWeekMapper teachingClassWeekMapper;
    @Resource
    private TeachingClassTeacherService teachingClassTeacherService;
    @Resource
    private PlanTeachingStudentService planTeachingStudentService;
    @Resource
    private TeachingClassWeekService teachingClassWeekService;
    @Resource
    private CourseWeekService courseWeekService;
    @Resource
    private TeacherService teacherService;
    @Resource
    private SubClassGroupService subClassGroupService;
    @Resource
    private CourseService courseService;
    @Resource
    private ScheduleMapper scheduleMapper;
    @Resource
    private CampusService campusService;
    @Resource
    private CollegeService collegeService;
    @Resource
    private PlanTeachingService planTeachingService;
    @Resource
    private StudentService studentService;
    @Resource
    private ScheduleConflictInfoService scheduleConflictInfoService;
    @Resource
    private TeachingClassStudentService teachingClassStudentService;
    @Resource
    private TypeService typeService;
    @Resource
    private MajorGradeService majorGradeService;
    @Resource
    private TaskInfoService taskInfoService;
    @Resource
    private StudentMapper studentMapper;
    @Resource
    private ScheduleService scheduleService;
    @Resource
    private ArrangeCourseService arrangeCourseService;
    @Resource
    private PlanTeachingCourseService planTeachingCourseService;
    @Resource
    @Lazy
    private YunBasicService yunBasicService;
    @Resource
    private MonitorRecordService monitorRecordService;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Integer deleteClass(List<Long> teachingClassIds) {
        if (CollUtil.isNotEmpty(teachingClassIds)) {
            teachingClassStudentMapper.delete(new LambdaQueryWrapper<TeachingClassStudent>().in(TeachingClassStudent::getTeachingClassId, teachingClassIds));
            teachingClassTeacherMapper.delete(new LambdaQueryWrapper<TeachingClassTeacher>().in(TeachingClassTeacher::getTeachingClassId, teachingClassIds));
            teachingClassWeekService.remove(new LambdaQueryWrapper<TeachingClassWeek>().in(TeachingClassWeek::getTeachingClassId, teachingClassIds));
            scheduleService.lambdaUpdate().in(Schedule::getTeachingClassId, teachingClassIds).remove();
            scheduleConflictInfoService.lambdaUpdate().in(ScheduleConflictInfo::getTeachingClassId, teachingClassIds).remove();
            monitorRecordService.lambdaUpdate().in(MonitorRecord::getTeachingClassId, teachingClassIds).remove();
            this.removeBatchByIds(teachingClassIds);
        }
        return teachingClassIds.size();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean combinedClass(List<Long> teachingClassIds, Long teachingClassId) {
        if (CollUtil.isEmpty(teachingClassIds) || teachingClassIds.size() < 2) {
            return false;
        }
        //将其他教学班合到该教学班
        TeachingClass teachingClass = teachingClassMapper.selectById(teachingClassId);
        List<TeachingClass> teachingClassList = this.lambdaQuery().in(TeachingClass::getTeachingClassId, teachingClassIds).list();
        int sum = teachingClassList.stream().mapToInt(TeachingClass::getClassNum).sum();
        List<String> collect = teachingClassList.stream().map(TeachingClass::getToClass).collect(Collectors.toList());
        StringBuilder toClass = new StringBuilder();
        for (TeachingClass aClass : teachingClassList) {
            if (ObjUtil.isNotEmpty(aClass.getToClass())) {
                toClass.append(aClass.getToClass());
                toClass.append(",");
            }
        }
        if (StringUtils.isNotBlank(toClass.toString())) {
            String temp = toClass.substring(0, toClass.length() - 1);
            teachingClass.setToClass(temp);
        }
        teachingClassIds.remove(teachingClassId);
        teachingClass.setClassNum(sum + teachingClass.getClassNum());
        this.updateById(teachingClass);
        //合并教师
//        teachingClassTeacherMapper.update(new TeachingClassTeacher().setTeachingClassId(teachingClassId), new LambdaQueryWrapper<TeachingClassTeacher>().in(TeachingClassTeacher::getTeachingClassId, teachingClassIds));
        //合并学生
        teachingClassStudentMapper.update(new TeachingClassStudent().setTeachingClassId(teachingClassId), new LambdaQueryWrapper<TeachingClassStudent>().in(TeachingClassStudent::getTeachingClassId, teachingClassIds));
        //删除教学班参数
        this.deleteClass(teachingClassIds);
        return true;
    }

    @Override
    public Long getTeachingClassNumByCourseId(Long courseId) {
        List<TeachingClass> teachingClassList = this.lambdaQuery().eq(TeachingClass::getCourseId, courseId)
                .select(TeachingClass::getTeachingClassName).list();
        Pattern r = Pattern.compile("(\\d+)(班)");
        long max = 0L;
        for (String teachingClassName : teachingClassList.stream().map(TeachingClass::getTeachingClassName).collect(Collectors.toList())) {
            Matcher matcher = r.matcher(teachingClassName);
            if (matcher.find()) {
                long num = Long.parseLong(matcher.group(1));
                if (num > max) {
                    max = num;
                }
            }
        }
        return max;
    }

    /**
     * 初始化教学班参数
     *
     * @param teachingClassList
     * @return
     */
    public List<TeachingClassWeek> initTeachingClassWeek(List<TeachingClass> teachingClassList) {
        //待新增教学班参数
        List<TeachingClassWeek> allTeachingClassWeeks = new ArrayList<>();
        //获取该课程对应课程参数
        List<Long> courseIds = teachingClassList.stream().map(TeachingClass::getCourseId).collect(Collectors.toList());
        Map<Long, List<CourseWeek>> courseWeekMap = courseWeekService.lambdaQuery().in(CourseWeek::getCourseId, courseIds).list()
                .stream().collect(Collectors.groupingBy(CourseWeek::getCourseId));
        //遍历教学班 生成教学班参数
        for (TeachingClass teachingClass : teachingClassList) {
            List<CourseWeek> courseWeeks = courseWeekMap.get(teachingClass.getCourseId());
            //遍历每个授课类型的课程参数生成教学班参数  教学班参数前端没传的话就由课程参数替代
            if (CollUtil.isNotEmpty(courseWeeks)) {
                courseWeeks.forEach(courseWeek -> {
                    TeachingClassWeek teachingClassWeek = new TeachingClassWeek();
                    //遍历前端传的教学班参数
                    Optional<TeachingClassWeek> front = teachingClass.getTeachingClassWeeks().stream()
                            .filter(a -> a.getHourType().equals(courseWeek.getHourType())).findFirst();
                    if (front.isPresent()) {
                        //存在的话就用前端传的
                        BeanUtil.copyProperties(front.get(), teachingClassWeek);
                        teachingClassWeek.setTeachingClassId(teachingClass.getTeachingClassId());
                    } else {
                        BeanUtil.copyProperties(courseWeek, teachingClassWeek);
                        teachingClassWeek.setTeachingClassId(teachingClass.getTeachingClassId());
                        teachingClassWeek.setNeedScheduleHour(courseWeek.getTotalHour());
                    }
                    allTeachingClassWeeks.add(teachingClassWeek);
                });
            }
        }
        List<Type> types = typeService.lambdaQuery().eq(Type::getTaskId, teachingClassList.get(0).getTaskId()).eq(Type::getFlag, 2).eq(Type::getTypeMode, 2).list();
        for (TeachingClassWeek week : allTeachingClassWeeks) {
            WeekDateVo dateVo = taskInfoService.countWeek(teachingClassList.get(0).getTaskId());
            if (StrUtil.isEmpty(week.getWeek())) {
                StringBuilder str = new StringBuilder();
                for (long i = 0; i < dateVo.getWeekCount(); i++) {
                    str.append("1");
                }
                week.setWeek(str.toString());
            }
            if (ObjUtil.isEmpty(week.getRoomType()) && CollUtil.isNotEmpty(types)) {
                week.setRoomType(types.get(0).getTypeId());
                week.setRoomTypeName(types.get(0).getTypeName());
            }
        }
        //环节的场地不需要默认值
        List<Long> ids = teachingClassList.stream().filter(a -> a.getFlag() == 2).map(TeachingClass::getTeachingClassId).collect(Collectors.toList());
        for (TeachingClassWeek teachingClassWeek : allTeachingClassWeeks.stream().filter(a -> ids.contains(a.getTeachingClassId())).collect(Collectors.toList())) {
            teachingClassWeek.setRoomType(null);
            teachingClassWeek.setRoomTypeName(null);
        }
        return allTeachingClassWeeks;
    }

    public List<TeachingClass> setAssessmentClass(List<TeachingClass> teachingClassList, Integer taskId) {
        Student student = studentService.lambdaQuery().eq(Student::getTaskId, taskId).list().get(0);
        for (TeachingClass teachingClass : teachingClassList) {
            Course course = courseService.getById(teachingClass.getCourseId());
            if (course.getAssessmentId() != null) {
                teachingClass.setAssessmentId(course.getAssessmentId());
                teachingClass.setAssessmentName(course.getAssessmentName());
            }
            if (teachingClass.getGradeId() == null) {
                teachingClass.setGradeId(student.getGradeId());
                teachingClass.setGradeName(student.getGradeName());
            }
        }
        return teachingClassList;
    }

    @Override
    public List<TeachingClassVo> getTeachingClassByCourseId(Long courseId) {
        //获取教学班
        List<TeachingClassVo> teachingClassVos = teachingClassMapper.getTeachingClassByCourseId(courseId);
        List<Long> teachingClassIds = teachingClassVos.stream().map(TeachingClassVo::getTeachingClassId).collect(Collectors.toList());
        if (CollUtil.isNotEmpty(teachingClassIds)) {
            //获取教学班教师
            Map<String, List<TeacherDto>> teacherMap = teacherService.getTeacherByTeachingClassIds(teachingClassIds)
                    .stream().collect(Collectors.groupingBy(o -> o.getTeachingClassId() + "-" + o.getHourType()));
            //获取授课类型数据
            Map<Long, List<TeachingClassWeek>> teachingClassWeekMap = teachingClassWeekService.lambdaQuery().in(TeachingClassWeek::getTeachingClassId, teachingClassIds).list()
                    .stream().collect(Collectors.groupingBy(TeachingClassWeek::getTeachingClassId));
            //遍历教学班为teachingClassHourVos赋值
            for (TeachingClassVo teachingClassVo : teachingClassVos) {
                teachingClassWeekMap.get(teachingClassVo.getTeachingClassId()).forEach(teachingClassWeek -> {
                    //对应一个授课类型数据
                    TeachingClassHourVo teachingClassHourVo = new TeachingClassHourVo();
                    BeanUtil.copyProperties(teachingClassWeek, teachingClassHourVo);
                    //教师信息
                    teachingClassHourVo.setTeachers(teacherMap.get(teachingClassHourVo.getTeachingClassId() + "-" + teachingClassHourVo.getHourType()));

                    teachingClassVo.getTeachingClassHourVos().add(teachingClassHourVo);
                });

            }
        }
        return teachingClassVos;
    }


    @Override
    public Object publishStatistics(Integer taskId) {
        Map<String, Object> map = new HashMap<>();
        List<String> basePlanIds = planTeachingService.lambdaQuery().eq(PlanTeaching::getTaskId, taskId).list()
                .stream().map(PlanTeaching::getBaseTeachingPlanId).collect(Collectors.toList());
        if (CollUtil.isEmpty(basePlanIds)) {
            throw new BizException("请先同步教学计划！");
        }
        List<PlanTeachingCourse> planTeachingCourseList = planTeachingCourseService.lambdaQuery().in(PlanTeachingCourse::getBaseTeachingPlanId, basePlanIds).list();
        List<String> baseCourseIds = planTeachingCourseList.stream().map(PlanTeachingCourse::getBaseCourseId).distinct().collect(Collectors.toList());
        List<Course> allCourseList = courseService.lambdaQuery().eq(Course::getTaskId, taskId).in(Course::getBaseCourseId, baseCourseIds).list();
        //开课课程数
        List<Course> courseList = allCourseList.stream().filter(a -> a.getFlag().equals(1)).collect(Collectors.toList());
        map.put("courseNum", courseList.size());
        //已分班课程数
        List<Course> doneCourseList = courseList.stream().filter(a -> a.getTeachingSet() == 1).collect(Collectors.toList());
        map.put("setTeachingClassCourseNum", (int) courseList.stream().filter(a -> a.getTeachingSet() == 1).count());
        //未分班课程数
        map.put("noTeachingClassCourseNum", courseList.size() - doneCourseList.size());
        //生成教学班数
        List<TeachingClass> teachingClassList = this.lambdaQuery().eq(TeachingClass::getTaskId, taskId)
                .eq(TeachingClass::getFlag, 1).eq(TeachingClass::getIsOptional, 0).list();
        map.put("courseTeachingClassNum", teachingClassList.size());
        //开课环节数
        List<Course> segmentList = allCourseList.stream().filter(a -> a.getFlag().equals(2)).collect(Collectors.toList());
        map.put("segmentNum", segmentList.size());
        //已分班环节数
        List<Course> doneSegmentList = segmentList.stream().filter(a -> a.getTeachingSet() == 1).collect(Collectors.toList());
        map.put("setTeachingClasSegmentNum", doneSegmentList.size());
        //未分班课程数
        map.put("noTeachingClasSegmentNum", segmentList.size() - doneSegmentList.size());
        //环节生成教学班数
        List<TeachingClass> segmentClassList = this.lambdaQuery().eq(TeachingClass::getTaskId, taskId)
                .eq(TeachingClass::getFlag, 2).eq(TeachingClass::getIsOptional, 0).list();
        map.put("segmentTeachingClassNum", segmentClassList.size());
        //各校区教学班分布情况
        List<TeachingClass> allTeachingClass = this.lambdaQuery().eq(TeachingClass::getTaskId, taskId).list();
        List<Map<String, Object>> campusTeachingClass = new ArrayList<>();
        List<Campus> campusList = campusService.lambdaQuery().eq(Campus::getTaskId, taskId).list();
        if (CollUtil.isNotEmpty(campusList)) {
            for (Campus item : campusList) {
                Map<String, Object> map1 = new HashMap<>();
                map1.put("name", item.getCampusName());
                map1.put("num", (int) allTeachingClass.stream().filter(a -> a.getCampusId().equals(item.getCampusId())).count());
                campusTeachingClass.add(map1);
            }
        }
        map.put("campusTeachingClass", campusTeachingClass);

        //各单位提交进度
        QueryWrapper<College> queryWrapper2 = new QueryWrapper<>();
        queryWrapper2.eq("task_id", taskId);
        List<CollegePlanDto> planDtos = new ArrayList<>();
        List<College> colleges = collegeService.list(queryWrapper2);
        int subCount = 0;
        int notSubCount = 0;
        for (College item : colleges
        ) {
            CollegePlanDto view = new CollegePlanDto();
            view.setCollegeName(item.getCollegeName());
            view.setFirstTime(item.getTeachingTaskFirstTime());
            view.setLatestTime(item.getTeachingTaskLatestTime());
            view.setPublishManName(item.getTeachingTaskUserName());
            if (item.getTeachingTaskFirstTime() == null) {
                view.setStatus(0);
                notSubCount += 1;
            } else {
                view.setStatus(1);
                subCount += 1;
            }
            planDtos.add(view);
        }
        //已提交
        map.put("subCount", subCount);
        //完成情况
        map.put("SubSituation", subCount / colleges.size() * 100);
        //开课单位数
        map.put("collegeCount", colleges.size());
        //开课单位详情
        map.put("collegeDetail", planDtos);
        return map;
    }

    @Override
    @Transactional
    public List<TeachingClass> addBatchTeachingClass(Integer taskId, List<TeachingClass> teachingClassList) {
        //教学班对应教师
        List<TeachingClassTeacher> teachingClassTeacherList = new ArrayList<>();
        //教学班对应学生
        List<TeachingClassStudent> teachingClassStudentList = new ArrayList<>();

        //批量添加教学班
        teachingClassList.forEach(a -> a.setIsEnable(0));
        this.saveOrUpdateBatch(setAssessmentClass(teachingClassList, taskId));
        //更新教学班参数
        List<TeachingClassWeek> allTeachingClassWeeks = this.initTeachingClassWeek(teachingClassList);

        Consumer<List<TeachingClassWeek>> teachingClassWeekConsumer = o -> teachingClassWeekMapper.addBatch(o);
        BatchInsert.batchSplitInsert(allTeachingClassWeeks, teachingClassWeekConsumer);
        //构建教学班学生实体类
        teachingClassList.forEach(teachingClass -> {
            teachingClass.getStudentIds().forEach(studentId -> {
                teachingClassStudentList.add(new TeachingClassStudent()
                        .setFlag(1)
                        .setTeachingClassId(teachingClass.getTeachingClassId())
                        .setCourseId(teachingClass.getCourseId())
                        .setStudentId(studentId));
            });

            teachingClass.getTeachingClassTeachers().forEach(teacherDto -> {
                teachingClassTeacherList.add(new TeachingClassTeacher()
                        .setTeachingClassId(teachingClass.getTeachingClassId())
                        .setTeacherId(teacherDto.getTeacherId())
                        .setHourType(teacherDto.getHourType()));
            });
        });
        //批量插入教学班教师，大数据批量插入
        Consumer<List<TeachingClassTeacher>> teacherConsumer = o -> teachingClassTeacherMapper.addBatch(o);
        BatchInsert.batchSplitInsert(teachingClassTeacherList, teacherConsumer);

        //批量插入教学班学生，大数据批量插入
        Consumer<List<TeachingClassStudent>> studentConsumer = o -> teachingClassStudentMapper.addBatch(o);
        BatchInsert.batchSplitInsert(teachingClassStudentList, studentConsumer);

        //更新课程状态
        List<Long> courseIdList = teachingClassList.stream().map(TeachingClass::getCourseId).collect(Collectors.toList());
        List<Course> courseList = courseService.lambdaQuery().eq(Course::getTaskId, teachingClassList.get(0).getTaskId()).list();
        List<Course> toUpdateCourseList = new ArrayList<>();
        for (Long courseId : courseIdList) {
            Optional<Course> optional = courseList.stream().filter(a -> a.getCourseId().equals(courseId)).findFirst();
            if (optional.isPresent()) {
                Course course = optional.get();
                course.setTeachingSet(1);
                course.setTeachingMode(1);
                toUpdateCourseList.add(course);
            }
        }
        courseService.updateBatchById(toUpdateCourseList);
        //填充教学班周次参数
//        teachingClassList.forEach(a -> {
//            List<TeachingClassWeek> weeks = teachingClassWeekService.lambdaQuery()
//                    .eq(TeachingClassWeek::getId, a.getTeachingClassId())
//                    .list();
//            a.setTeachingClassWeeks(weeks);
//        });
        return teachingClassList;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<TeachingClass> addTeachingClassByClassId(Integer taskId, Long courseId, Integer teachingClassType, List<Integer> planIds) {
        Course course = courseService.getById(courseId);
        courseService.lambdaUpdate().eq(Course::getCourseId, courseId).eq(Course::getTaskId, taskId)
                .set(Course::getTeachingSet, 1).set(Course::getTeachingMode, 3).update();
        List<TeachingClass> result = new ArrayList<>();
        if (CollUtil.isEmpty(planIds)) {
            throw new BizException("请选择要按行政班生成的培养计划！");
        }
        List<PlanTeaching> planTeachings = planTeachingService.lambdaQuery().eq(PlanTeaching::getTaskId, taskId).in(PlanTeaching::getTeachingPlanId, planIds).list();
        List<String> basePlanIds = planTeachings.stream().map(PlanTeaching::getBaseTeachingPlanId).collect(Collectors.toList());
        List<PlanTeachingStudent> planTeachingStudentList = planTeachingStudentService.lambdaQuery().eq(PlanTeachingStudent::getTaskId, taskId).in(PlanTeachingStudent::getBaseTeachingPlanId, basePlanIds).list();
        List<String> baseStudentIds = planTeachingStudentList.stream().map(PlanTeachingStudent::getBaseStudentId).collect(Collectors.toList());
        if (CollUtil.isEmpty(baseStudentIds)) {
            throw new BizException("该培养计划中不存在学生，无法生成！");
        }
        List<Student> students = studentService.lambdaQuery().eq(Student::getTaskId, taskId).in(Student::getBaseStudentId, baseStudentIds).list();
        if (CollUtil.isEmpty(students)) {
            throw new BizException("该培养计划中不存在学生，无法生成！");
        }
        MajorGrade majorGrade = majorGradeService.lambdaQuery().eq(MajorGrade::getTaskId, taskId)
                .eq(MajorGrade::getBaseCollegeId, planTeachings.get(0).getBaseCollegeId())
                .eq(MajorGrade::getBaseMajorId, planTeachings.get(0).getBaseMajorId())
                .eq(MajorGrade::getGradeId, planTeachings.get(0).getGradeId())
                .list().get(0);
        //保存数据
        List<TeachingClassStudent> teachingClassStudents = new ArrayList<>();
        Map<String, List<Student>> studentMap = students.stream().collect(Collectors.groupingBy(Student::getClassName));
        for (Map.Entry<String, List<Student>> studentEntry : studentMap.entrySet()) {
            String className = studentEntry.getKey();
            List<Student> studentList = studentEntry.getValue();
            String baseTeachingPlanId = planTeachingStudentList.stream().filter(a -> a.getBaseStudentId().equals(studentList.get(0).getBaseStudentId())).findFirst().get().getBaseTeachingPlanId();
            PlanTeaching planTeaching = planTeachings.stream().filter(a -> a.getBaseTeachingPlanId().equals(baseTeachingPlanId)).findFirst().get();
            TeachingClass model = new TeachingClass();
            BeanUtils.copyProperties(studentList.get(0), model);
            BeanUtils.copyProperties(course, model);
            model.setTeachingClassName(course.getCourseName() + "-" + className);
            model.setClassNum(studentList.size());
            model.setToClass(studentList.get(0).getClassId());
            model.setTeachingClassType(teachingClassType);
            model.setStudyNature(planTeaching.getStudyNature());
            model.setCampusId(studentList.get(0).getCampusId() == null ? majorGrade.getCampusId() : Integer.valueOf(studentList.get(0).getCampusId()));
            model.setCampusName(studentList.get(0).getCampusName() == null ? majorGrade.getCampusName() : studentList.get(0).getCampusName());
            result.add(model);
            this.save(model);
            //构建教学班学生实体类
            studentList.forEach(student -> {
                TeachingClassStudent teachingClassStudent = new TeachingClassStudent()
                        .setTeachingClassId(model.getTeachingClassId())
                        .setStudentId(student.getStudentId())
                        .setCourseId(courseId)
                        .setFlag(1);
                teachingClassStudents.add(teachingClassStudent);
            });
        }
        //批量插入教学班学生，大数据批量插入
        Consumer<List<TeachingClassStudent>> studentConsumer = o -> teachingClassStudentMapper.addBatch(o);
        BatchInsert.batchSplitInsert(teachingClassStudents, studentConsumer);

        List<TeachingClassWeek> allTeachingClassWeeks = this.initTeachingClassWeek(result);
        Consumer<List<TeachingClassWeek>> teachingClassWeekConsumer = o -> teachingClassWeekMapper.addBatch(o);
        BatchInsert.batchSplitInsert(allTeachingClassWeeks, teachingClassWeekConsumer);

        return result;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<TeachingClass> spiltClassForTeacher(Integer taskId, Long teachingClassId, Long splitNum, Integer hourType, List<Teacher> teacherList) {
        TeachingClass teachingClass = this.getById(teachingClassId);
        List<TeachingClassWeek> weeks = teachingClassWeekService.lambdaQuery().eq(TeachingClassWeek::getTeachingClassId, teachingClass.getTeachingClassId()).list();
        List<TeachingClassStudent> students = teachingClassStudentService.lambdaQuery().eq(TeachingClassStudent::getTeachingClassId, teachingClass.getTeachingClassId()).eq(TeachingClassStudent::getFlag, 1).list();
        List<TeachingClassTeacher> classTeachers = teachingClassTeacherService.lambdaQuery().eq(TeachingClassTeacher::getTeachingClassId, teachingClass.getTeachingClassId()).list();
        List<Teacher> teacherList1 = teacherService.lambdaQuery().eq(Teacher::getTaskId, taskId).list();
        List<TeachingClass> result = new ArrayList<>();
        String uuid = StringUtils.isNotBlank(teachingClass.getSplitTeacherUuid()) ? teachingClass.getSplitTeacherUuid() : UUID.randomUUID().toString();
        List<TeachingClassStudent> toSaveStudentList = new ArrayList<>();
        List<TeachingClassWeek> toSaveWeekList = new ArrayList<>();
        List<TeachingClassTeacher> toSaveTeacherList = new ArrayList<>();
        for (int i = 1; i < splitNum; i++) {
            //保存教学班
            TeachingClass newClass = new TeachingClass();
            BeanUtils.copyProperties(teachingClass, newClass);
            newClass.setTeachingClassId(null);
            newClass.setSplitTeacherUuid(uuid);
            this.save(newClass);
            result.add(newClass);
            //保存教学班学生
            for (TeachingClassStudent student : students) {
                TeachingClassStudent newStudent = new TeachingClassStudent();
                BeanUtils.copyProperties(student, newStudent);
                newStudent.setId(null);
                newStudent.setTeachingClassId(newClass.getTeachingClassId());
                toSaveStudentList.add(newStudent);
            }
            for (TeachingClassWeek week : weeks) {
                if (!week.getHourType().equals(hourType)) {
                    continue;
                }
                TeachingClassWeek newWeek = new TeachingClassWeek();
                BeanUtils.copyProperties(week, newWeek);
                newWeek.setId(null);
                newWeek.setTotalHour(0);
                newWeek.setWeekNum(0);
                newWeek.setConnectNumber(0);
                newWeek.setConnectSection(0);
                newWeek.setWeek(newWeek.getWeek().replace("1", "0"));
                newWeek.setTeachingClassId(newClass.getTeachingClassId());
                toSaveWeekList.add(newWeek);
            }
            TeachingClassTeacher newTeacher = new TeachingClassTeacher()
                    .setTeachingClassId(newClass.getTeachingClassId())
                    .setHourType(hourType);
            Teacher teacher = teacherList.get(i);
            Optional<Teacher> optional = teacherList1.stream().filter(a -> a.getBaseTeacherId().equals(teacher.getBaseTeacherId())).findFirst();
            if (optional.isPresent()) {
                newTeacher.setTeacherId(optional.get().getTeacherId());
            } else {
                teacherService.save(teacher);
                newTeacher.setTeacherId(teacher.getTeacherId());
            }
            toSaveTeacherList.add(newTeacher);
        }
        //更新原本的教学班
        teachingClass.setSplitTeacherUuid(uuid);
        this.updateById(teachingClass);
//        for (TeachingClassWeek week : weeks) {
//            week.setTotalHour(0);
//            week.setWeekNum(0);
//            week.setConnectNumber(0);
//            week.setConnectSection(0);
//            week.setWeek(week.getWeek().replace("1", "0"));
//        }
//        teachingClassWeekService.updateBatchById(weeks);
        //查询该教学班，该授课方式中的所有老师
        List<Long> teacherIds = teachingClassTeacherService.lambdaQuery()
                .eq(TeachingClassTeacher::getTeachingClassId, teachingClassId)
                .eq(TeachingClassTeacher::getHourType, hourType)
                .list()
                .stream().map(TeachingClassTeacher::getTeacherId).collect(Collectors.toList());
        //判空操作，防止sql语句错误导致报错
        if (CollUtil.isNotEmpty(teacherIds)) {
            //获取教师表所有老师
            List<Teacher> teachers = teacherService.lambdaQuery().eq(Teacher::getTaskId, taskId).in(Teacher::getTeacherId, teacherIds).list();
            List<Long> removeTeacherIds = new ArrayList<>();
            teachers.forEach(a -> {
                if (a.getIdentity().equals(1)) {
                    //获取要删除的教师
                    removeTeacherIds.add(a.getTeacherId());
                }
            });
            //判空操作，防止sql语句错误导致报错
            if (CollUtil.isNotEmpty(removeTeacherIds)) {
                //删除老师
                teachingClassTeacherService.lambdaUpdate()
                        .eq(TeachingClassTeacher::getTeachingClassId, teachingClassId)
                        .eq(TeachingClassTeacher::getHourType, hourType)
                        .in(TeachingClassTeacher::getTeacherId, removeTeacherIds)
                        .remove();
            }
        }
        TeachingClassTeacher newTeacher = new TeachingClassTeacher()
                .setTeachingClassId(teachingClass.getTeachingClassId())
                .setHourType(hourType);
        Teacher teacher = teacherList.get(0);
        Optional<Teacher> optional = teacherList1.stream().filter(a -> a.getBaseTeacherId().equals(teacher.getBaseTeacherId())).findFirst();
        if (optional.isPresent()) {
            newTeacher.setTeacherId(optional.get().getTeacherId());
        } else {
            teacherService.save(teacher);
            newTeacher.setTeacherId(teacher.getTeacherId());
        }
        teachingClassTeacherService.save(newTeacher);

        //保存拆教师之后的教学班
        teachingClassStudentService.saveBatch(toSaveStudentList);
        teachingClassWeekService.saveBatch(toSaveWeekList);
        teachingClassTeacherService.saveBatch(toSaveTeacherList);
        return result;
    }

    @Override
    public Boolean confirmTeachTask(List<String> baseCollegeIdList, String userId, String userName, Integer taskId) {
        List<College> collegeList = collegeService.lambdaQuery().eq(College::getTaskId, taskId).list();
        if (CollUtil.isEmpty(baseCollegeIdList)) {
            //前端不传 == 教务管理员提交全部学院
            baseCollegeIdList = collegeList.stream().map(College::getBaseCollegeId).collect(Collectors.toList());
        }
        List<College> todoColleges = new ArrayList<>();
        for (String baseCollegeId : baseCollegeIdList
        ) {
            List<College> colleges = collegeList.stream().filter(a -> a.getBaseCollegeId().equals(baseCollegeId)).collect(Collectors.toList());
            for (College item : colleges
            ) {
                if (item.getTeachingTaskFirstTime() == null) {
                    item.setTeachingTaskFirstTime(LocalDateTime.now());
                }
                item.setTeachingTaskLatestTime(LocalDateTime.now());
                item.setTeachingTaskUserId(userId);
                try {
                    item.setTeachingTaskUserName(URLDecoder.decode(userName, "utf-8"));
                } catch (UnsupportedEncodingException e) {
                    throw new RuntimeException(e);
                }
                todoColleges.add(item);
            }
        }
        collegeService.updateBatchById(todoColleges);
        return true;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<TeachingClassTeacher> updateTeacher(Integer taskId, Long teachingClassId, Integer hourType, List<Teacher> teacherList, Integer type, Integer identity) {
        if (type != null) {
            if (type == 1) {
                //当前为自学设置教学班教师
                hourType = 4;   //自学模式下授课类型统一设值为其他
            }
        }
        //查询该教学班，该授课方式中的所有老师
        List<Long> teacherIds = teachingClassTeacherService.lambdaQuery()
                .eq(TeachingClassTeacher::getTeachingClassId, teachingClassId)
                .eq(TeachingClassTeacher::getHourType, hourType)
                .list()
                .stream().map(TeachingClassTeacher::getTeacherId).collect(Collectors.toList());
        //判空操作，防止sql语句错误导致报错
        if (CollUtil.isNotEmpty(teacherIds)) {
            //获取教师表所有老师
            List<Teacher> teachers = teacherService.lambdaQuery().eq(Teacher::getTaskId, taskId).in(Teacher::getTeacherId, teacherIds).list();
            List<Long> removeTeacherIds = new ArrayList<>();
            teachers.forEach(a -> {
                if (a.getIdentity().equals(identity)) {
                    //获取要删除的教师
                    removeTeacherIds.add(a.getTeacherId());
                }
            });
            //判空操作，防止sql语句错误导致报错
            if (CollUtil.isNotEmpty(removeTeacherIds)) {
                //删除老师
                teachingClassTeacherService.lambdaUpdate()
                        .eq(TeachingClassTeacher::getTeachingClassId, teachingClassId)
                        .eq(TeachingClassTeacher::getHourType, hourType)
                        .in(TeachingClassTeacher::getTeacherId, removeTeacherIds)
                        .remove();
            }
        }
        //教学班对应教师
        List<TeachingClassTeacher> teachingClassTeacherList = new ArrayList<>();
        if (CollUtil.isNotEmpty(teacherList)) {
            List<Teacher> teacherList1 = teacherService.lambdaQuery().eq(Teacher::getTaskId, taskId).list();
            for (Teacher item : teacherList) {
                //创建教学班-教师实体类
                TeachingClassTeacher view = new TeachingClassTeacher()
                        .setTeachingClassId(teachingClassId)
                        .setHourType(hourType);
                //判断教师表是否存在该教师
                Optional<Teacher> optional = teacherList1.stream().filter(a -> a.getBaseTeacherId().equals(item.getBaseTeacherId())).findFirst();
                if (optional.isPresent()) {
                    //存在则获取id
                    if (!optional.get().getIdentity().equals(item.getIdentity()) && item.getIdentity() == 1) {
                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                        throw new BizException(item.getTeacherName() + ",该老师不是任课教师");
                    } else if (!optional.get().getIdentity().equals(item.getIdentity()) && item.getIdentity() == 2) {
                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                        throw new BizException(item.getTeacherName() + ",该老师不是助教教师");
                    }
                    view.setTeacherId(optional.get().getTeacherId());
                } else {
                    //不存在先保存到教师表，再获取id
                    teacherService.save(item);
                    view.setTeacherId(item.getTeacherId());
                }
                //保存实体类
                teachingClassTeacherList.add(view);
            }
        }
        teachingClassTeacherService.saveBatch(teachingClassTeacherList);
        if (scheduleService.lambdaQuery().eq(Schedule::getTaskId, taskId).isNotNull(Schedule::getTimeCode).count() > 0) {
            TaskInfo taskInfo = taskInfoService.getById(taskId);
            arrangeCourseService.manualAdjustmentUpdate(taskInfo.getSchoolId(), taskInfo.getTerm(), taskId, null, teachingClassId);
        }
        return teachingClassTeacherList;
    }

    @Override
    public List<TeachingClass> getByUniqueShiftSign(String uniqueShiftSign) {
        //获取教学班
        List<TeachingClass> list = teachingClassMapper.getTeachingClassByShiftsign(uniqueShiftSign);
        List<CourseWeek> courseWeekList = courseWeekService.lambdaQuery().list();
        for (TeachingClass item : list) {
            List<CourseWeek> weekList = courseWeekList.stream().filter(a -> a.getCourseId().equals(item.getCourseId())).collect(Collectors.toList());
            Integer weekNum = 0;
            for (CourseWeek week : weekList) {
                weekNum += week.getWeekNum();
            }
            item.setWeekNum(weekNum);
        }
        //填充教师信息
        List<Long> teachingClassIds = list.stream().map(TeachingClass::getTeachingClassId).collect(Collectors.toList());
        Map<Long, List<TeachingClassTeacher>> collect = teachingClassTeacherService.lambdaQuery()
                .in(TeachingClassTeacher::getTeachingClassId, teachingClassIds)
                .list()
                .stream().collect(Collectors.groupingBy(TeachingClassTeacher::getTeachingClassId));
        list.forEach(a -> a.setTeachingClassTeachers(collect.get(a.getTeachingClassId())));
        //填充周次数据
        if (CollUtil.isNotEmpty(teachingClassIds)) {
            List<TeachingClassWeek> teachingClassWeekList = teachingClassWeekService.list(new LambdaQueryWrapper<TeachingClassWeek>().in(TeachingClassWeek::getTeachingClassId, teachingClassIds));
            Map<Long, List<TeachingClassWeek>> weekMap = teachingClassWeekList.stream().collect(Collectors.groupingBy(TeachingClassWeek::getTeachingClassId));
            list.forEach(a -> a.setTeachingClassWeeks(weekMap.get(a.getTeachingClassId())));
        }
        return list;
    }


    @Override
    public List<SubGroupVo> getClassGroupList(Integer taskId, String uniqueShiftSign) {
        List<SubGroupVo> res = new ArrayList<>();
        List<SubClassGroup> subGroupList = subClassGroupService.lambdaQuery()
                .eq(SubClassGroup::getTaskId, taskId)
                .eq(SubClassGroup::getUniqueShiftSign, uniqueShiftSign)
                .list();

        if (CollUtil.isNotEmpty(subGroupList)) {
            Map<String, List<SubClassGroup>> map = subGroupList.stream().collect(Collectors.groupingBy(SubClassGroup::getUniqueGroupSign));
            for (Map.Entry<String, List<SubClassGroup>> entry : map.entrySet()) {
                String subGroupId = entry.getKey();
                List<SubClassGroup> groupList = entry.getValue();
                SubGroupVo subGroupVo = new SubGroupVo();
                subGroupVo.setUniqueGroupSign(subGroupId);
                subGroupVo.setGroupName(groupList.get(0).getGroupName());
                subGroupVo.setSubGroups(groupList);
                subGroupVo.setWeekNum(groupList.get(0).getWeekNum());
                res.add(subGroupVo);
            }
        }
        res.sort(Comparator.comparing(SubGroupVo::getGroupName));
        return res;
    }

    @Override
    public ResultDto<TeachingClass> getTeachingClassHourList(Integer currentPage, Integer pageSize, Integer taskId, Integer flag, Integer campusId, String collegeId, String gradeId, String baseMajorId, String keyWord, Long teacherId) {
        ResultDto<TeachingClass> result = new ResultDto<>();
        List<Teacher> teacherList1 = teacherService.lambdaQuery().eq(Teacher::getTaskId, taskId).list();
        List<Course> courseList = courseService.lambdaQuery().eq(Course::getTaskId, taskId).list();
        List<Student> studentList1 = studentService.lambdaQuery().eq(Student::getTaskId, taskId).list();
        //获取教学班
        List<TeachingClass> teachingClassList = this.lambdaQuery()
                .eq(TeachingClass::getTaskId, taskId)
                .eq(ObjUtil.isNotEmpty(flag), TeachingClass::getFlag, flag)
                .eq(ObjUtil.isNotEmpty(campusId), TeachingClass::getCampusId, campusId)
                .eq(StrUtil.isNotEmpty(collegeId), TeachingClass::getBaseCollegeId, collegeId)
                .eq(StringUtils.isNotBlank(gradeId), TeachingClass::getGradeId, gradeId)
                .eq(StringUtils.isNotBlank(baseMajorId), TeachingClass::getBaseMajorId, baseMajorId)
                .like(StringUtils.isNotBlank(keyWord), TeachingClass::getTeachingClassName, keyWord)
                .eq(TeachingClass::getIsOptional, 0)
//                .ne(TeachingClass::getTeachingClassType,0)
                .isNull(TeachingClass::getUniqueShiftSign)
                .list();
        List<TeachingClassWeek> weekList = teachingClassWeekService.list();
        List<TeachingClassTeacher> teacherList = teachingClassTeacherService.list();
        List<TeachingClassStudent> studentList = teachingClassStudentService.lambdaQuery().eq(TeachingClassStudent::getFlag, 1).list();
        List<TeachingClass> newClassList = new ArrayList<>();
        List<TeachingClass> addClass = new ArrayList<>();
        for (TeachingClass teachingClass : teachingClassList) {
            if (StringUtils.isNotBlank(teachingClass.getSplitTeacherUuid())) {
                List<TeachingClass> splitTeacherClassList = teachingClassList.stream().filter(a -> a.getSplitTeacherUuid() != null && a.getSplitTeacherUuid().equals(teachingClass.getSplitTeacherUuid())).collect(Collectors.toList());
                List<Long> splitClassIds = splitTeacherClassList.stream().map(TeachingClass::getTeachingClassId).collect(Collectors.toList());
                //获取教学班周数
                List<TeachingClassWeek> teachingClassWeek = weekList.stream()
                        .filter(a -> splitClassIds.contains(a.getTeachingClassId()))
                        .collect(Collectors.toList());
                for (TeachingClassWeek item : teachingClassWeek) {
                    switch (item.getHourType()) {
                        case 1:
                            item.setHourTypeName("讲授");
                            break;
                        case 2:
                            item.setHourTypeName("实验");
                            break;
                        case 3:
                            item.setHourTypeName("上机");
                            break;
                        case 4:
                            item.setHourTypeName("其他");
                            break;
                        default:
                            break;
                    }
                }
                teachingClass.setTeachingClassWeeks(teachingClassWeek);
                //获取教学班老师
                List<TeachingClassTeacher> teachingClassTeacher = teacherList.stream()
                        .filter(a -> splitClassIds.contains(a.getTeachingClassId()))
                        .collect(Collectors.toList());
                for (TeachingClassTeacher item : teachingClassTeacher) {
                    Teacher teacher = teacherList1.stream().filter(a -> a.getTeacherId().equals(item.getTeacherId())).findFirst().get();
                    item.setIdentity(teacher.getIdentity())
                            .setImageUrl(teacher.getImageUrl())
                            .setTeacherName(teacher.getTeacherName())
                            .setBaseTeacherId(teacher.getBaseTeacherId());
                    switch (item.getHourType()) {
                        case 1:
                            item.setHourTypeName("讲授");
                            break;
                        case 2:
                            item.setHourTypeName("实验");
                            break;
                        case 3:
                            item.setHourTypeName("上机");
                            break;
                        case 4:
                            item.setHourTypeName("其他");
                            break;
                        default:
                            break;
                    }
                }
                teachingClass.setTeachingClassTeachers(teachingClassTeacher);
                addClass.add(teachingClass);
            } else {
                //获取教学班周数
                List<TeachingClassWeek> teachingClassWeek = weekList.stream()
                        .filter(a -> a.getTeachingClassId().equals(teachingClass.getTeachingClassId()))
                        .collect(Collectors.toList());
                for (TeachingClassWeek item : teachingClassWeek) {
                    switch (item.getHourType()) {
                        case 1:
                            item.setHourTypeName("讲授");
                            break;
                        case 2:
                            item.setHourTypeName("实验");
                            break;
                        case 3:
                            item.setHourTypeName("上机");
                            break;
                        case 4:
                            item.setHourTypeName("其他");
                            break;
                        default:
                            break;
                    }
                }
                teachingClass.setTeachingClassWeeks(teachingClassWeek);
                //获取教学班老师
                List<TeachingClassTeacher> teachingClassTeacher = teacherList.stream()
                        .filter(a -> a.getTeachingClassId().equals(teachingClass.getTeachingClassId()))
                        .collect(Collectors.toList());
                for (TeachingClassTeacher item : teachingClassTeacher) {
                    Teacher teacher = teacherList1.stream().filter(a -> a.getTeacherId().equals(item.getTeacherId())).findFirst().get();
                    item.setIdentity(teacher.getIdentity())
                            .setImageUrl(teacher.getImageUrl())
                            .setTeacherName(teacher.getTeacherName())
                            .setBaseTeacherId(teacher.getBaseTeacherId());
                    switch (item.getHourType()) {
                        case 1:
                            item.setHourTypeName("讲授");
                            break;
                        case 2:
                            item.setHourTypeName("实验");
                            break;
                        case 3:
                            item.setHourTypeName("上机");
                            break;
                        case 4:
                            item.setHourTypeName("其他");
                            break;
                        default:
                            break;
                    }
                }
                teachingClass.setTeachingClassTeachers(teachingClassTeacher);
                newClassList.add(teachingClass);
            }
        }
        List<String> uuids = addClass.stream().map(TeachingClass::getSplitTeacherUuid).distinct().collect(Collectors.toList());
        for (String uuid : uuids) {
            TeachingClass view = addClass.stream().filter(a -> a.getSplitTeacherUuid().equals(uuid)).collect(Collectors.toList()).get(0);
            newClassList.add(view);
        }
        //按老师筛选
        if (ObjUtil.isNotEmpty(teacherId)) {
            //临时list容器
            List<TeachingClass> tempClassList = new ArrayList<>();
            for (TeachingClass teachingClass : newClassList) {
                List<Long> teacherIds = teachingClass.getTeachingClassTeachers().stream().map(TeachingClassTeacher::getTeacherId).collect(Collectors.toList());
                if (CollUtil.isNotEmpty(teacherIds) && teacherIds.contains(teacherId)) {
                    //教学班教室包含该老师则添加
                    tempClassList.add(teachingClass);
                }
            }
            newClassList = tempClassList;
        }
        for (TeachingClass teachingClass : newClassList) {
            Optional<Course> optionalCourse = courseList.stream().filter(a -> a.getCourseId().equals(teachingClass.getCourseId())).findFirst();
            if (optionalCourse.isPresent()) {
                Course course = optionalCourse.get();
                teachingClass.setTotalHour(course.getLectureHour() + course.getOtherHour() + course.getExperimentalHour() + course.getComputerHour());
            } else {
                teachingClass.setTotalHour(0);
            }
        }
        result.setTotal((long) newClassList.size());
        result.setPages((long) (newClassList.size() % pageSize == 0 ? newClassList.size() / pageSize : newClassList.size() / pageSize + 1));
        //分页
        newClassList = newClassList.stream()
                .sorted(Comparator.comparing(TeachingClass::getTeachingClassId))
                .skip((long) (currentPage - 1) * pageSize)
                .limit(pageSize)
                .collect(Collectors.toList());
        result.setCurrentPage(currentPage);
        result.setPageSize(pageSize);
        result.setList(newClassList);
        return result;
    }

    @Override
    public PageInfo<TeachingClassHourVo> getTeachingClassHourList(Page<TeachingClassHourVo> page, Integer taskId, Integer flag, Integer campusId, String collegeId, String gradeId, String baseMajorId, String keyWord, Long teacherId) {
        Page<TeachingClassHourVo> teachingClassHourVo = teachingClassMapper.getTeachingClassHourVo(page, taskId, flag, campusId, collegeId, gradeId, baseMajorId, null, keyWord, teacherId);
        List<TeachingClassHourVo> teachingClassHourList = teachingClassHourVo.getRecords();
        List<Teacher> teacherList = teacherService.lambdaQuery().eq(Teacher::getTaskId, taskId).list();
        List<Student> studentList = studentService.lambdaQuery().eq(Student::getTaskId, taskId).list();
        for (TeachingClassHourVo classHourVo : teachingClassHourList) {
            switch (classHourVo.getHourType()) {
                case 1:
                    classHourVo.setHourTypeName("讲授");
                    break;
                case 2:
                    classHourVo.setHourTypeName("实验");
                    break;
                case 3:
                    classHourVo.setHourTypeName("上机");
                    break;
                case 4:
                    classHourVo.setHourTypeName("其他");
                    break;
                default:
                    break;
            }
            //填充教师信息
            List<TeachingClassTeacher> teachingClassTeacherList = teachingClassTeacherService.lambdaQuery()
                    .eq(TeachingClassTeacher::getTeachingClassId, classHourVo.getTeachingClassId())
                    .list();
            teachingClassTeacherList.forEach(a -> {
                Optional<Teacher> teacherOptional = teacherList.stream().filter(t -> t.getTeacherId().equals(a.getTeacherId())).findFirst();
                if (teacherOptional.isPresent()) {
                    Teacher teacher = teacherOptional.get();
                    a.setImageUrl(teacher.getImageUrl());
                    a.setTeacherName(teacher.getTeacherName());
                    a.setBaseTeacherId(teacher.getBaseTeacherId());
                    a.setIdentity(teacher.getIdentity());
                }
            });
            classHourVo.setTeacherList(teachingClassTeacherList);
            //填充学生信息
            List<TeachingClassStudent> teachingClassStudents = teachingClassStudentService.lambdaQuery()
                    .eq(TeachingClassStudent::getTeachingClassId, classHourVo.getTeachingClassId())
                    .eq(TeachingClassStudent::getFlag, 1)
                    .list();
            String stuNames = "";
            for (int i = 0; i < teachingClassStudents.size(); i++) {
                TeachingClassStudent teachingClassStudent = teachingClassStudents.get(i);
                Optional<Student> optionalStudent = studentList.stream().filter(s -> s.getStudentId().equals(teachingClassStudent.getStudentId())).findFirst();
                if (optionalStudent.isPresent()) {
                    Student student = optionalStudent.get();
                    stuNames = stuNames + student.getStudentName() + ",";
                }
            }
            stuNames = stuNames.substring(0, stuNames.length() - 1);
            classHourVo.setStuNames(stuNames);
        }
        return PagingUtil.formatPageResult(teachingClassHourVo);
    }


    @Override
    public List<TeachingClassWeekScheduleDto> getTeachingClassAllSchedule(Integer taskId, List<TeachingClassWeekScheduleDto> teachingClassTeachers, String timeCodes) {
        List<TeachingClassWeekScheduleDto> teachingClassList = new ArrayList<>();
        if (CollUtil.isEmpty(teachingClassTeachers)) {
            return teachingClassList;
        }
        //term教学班
        teachingClassList = teachingClassMapper.getTeachingClassScheduleTeacher(null, teachingClassTeachers);


        if (CollUtil.isNotEmpty(teachingClassList)) {
            List<Long> teachingClassIds = teachingClassList.stream().map(TeachingClassWeekScheduleDto::getTeachingClassId).collect(Collectors.toList());
            //补充教师信息
            Map<Long, List<TeacherDto>> teachingClassToTeacher = teacherService.getTeacherByTeachingClassIds(teachingClassIds)
                    .stream().collect(Collectors.groupingBy(TeacherDto::getTeachingClassId));

            //当前冲突信息
            List<ScheduleConflictInfo> cnoflictList = scheduleConflictInfoService.list(
                    new LambdaQueryWrapper<ScheduleConflictInfo>()
                            .eq(ScheduleConflictInfo::getTaskId, taskId)
                            .in(ScheduleConflictInfo::getTeachingClassId, teachingClassIds));

            Map<Long, List<ScheduleConflictInfo>> cnoflictMap = cnoflictList.stream()
                    .collect(Collectors.groupingBy(ScheduleConflictInfo::getTeachingClassId));

            //课表信息
            List<ScheduleDto> scheduleDtoList = scheduleMapper.getAllScheduleByTeachingClassIds(taskId, teachingClassIds);
            Map<Long, List<ScheduleDto>> scheduleMap = scheduleDtoList.stream().collect(Collectors.groupingBy(ScheduleDto::getTeachingClassId));

            teachingClassList.forEach(a -> {
                //多教师版本
                List<TeacherDto> teachers = teachingClassToTeacher.getOrDefault(a.getTeachingClassId(), ListUtil.empty());
                teachers = teachers.stream().filter(t -> Objects.equals(t.getHourType(), a.getHourType())).collect(Collectors.toList());
                a.setTeachers(teachers);
                //冲突
                if (CollUtil.isNotEmpty(cnoflictList)) {
                    List<ScheduleConflictInfo> scheduleConflictInfos = cnoflictMap.get(a.getTeachingClassId());
                    if (CollUtil.isNotEmpty(scheduleConflictInfos)) {
                        a.setConflicts(scheduleConflictInfos.stream()
                                .filter(o -> o.getHourType().equals(a.getHourType()))
                                .collect(Collectors.toList()));
                    }
                }

                String teacherName = teachers.stream().map(TeacherDto::getTeacherName).collect(Collectors.joining(","));
                //课表
                if (CollUtil.isNotEmpty(scheduleDtoList)) {
                    List<ScheduleDto> scheduleDtos = scheduleMap.get(a.getTeachingClassId());
                    if (CollUtil.isNotEmpty(scheduleDtos)) {
                        List<ScheduleDto> schedules = scheduleDtos.stream()
                                .filter(o -> o.getHourType().equals(a.getHourType()) && StrUtil.isNotEmpty(o.getTimeCode()))
                                .peek(o -> {
                                    o.setTeacherName(teacherName);
                                }).collect(Collectors.toList());
                        if (StrUtil.isNotEmpty(timeCodes)) {
                            schedules = schedules.stream()
                                    .filter(o -> StrUtil.isNotEmpty(o.getTimeCode()) && timeCodes.contains(o.getTimeCode()))
                                    .collect(Collectors.toList());
                        }
                        a.setSchedules(schedules);
                    }
                }
            });
        }
        return teachingClassList;
    }

    //    @Override
    public String allTeachingClassToExcel0(Integer taskId, String importMode) {
        String modelPath = GlobalConstant.MODEL_EXCEL_PATH + "【模板】教学班信息 (大学排课).xls";
        TaskInfo taskInfo = taskInfoService.getById(taskId);
        String storePath = "/" + taskInfo.getTermName() + "/syncTeachingClass.xlsx";
        String targetPath = GlobalConstant.OUTPUT_EXCEL_PATH + storePath;

        FileUtil.copy(modelPath, targetPath, true);
        ExcelWriter writer = ExcelUtil.getWriter(targetPath);
        writer.setSheet(0);
        writer.passCurrentRow();
        writer.passCurrentRow();
        String httpPath = "/static/OutputExcel" + storePath;

        //课程教学班
        List<SyncTeachingClassDto> courseTeachingClassList = teachingClassMapper.syncCourseTeachingClassDto(taskId, 0);
        //环节教学班
        List<SyncTeachingClassDto> segmentTeachingClassList = teachingClassMapper.syncSegmentTeachingClassDto(taskId);
        courseTeachingClassList.addAll(segmentTeachingClassList);
        if (CollUtil.isEmpty(courseTeachingClassList)) {
            writer.close();
            return httpPath;
        }
        List<Long> teachingClassIds = courseTeachingClassList.stream().map(SyncTeachingClassDto::getTeachingClassId).collect(Collectors.toList());
        //获取行政班 及对应年级
        Map<String, ClassVo> classMap = studentMapper.getClassDto(taskId, null, null, null)
                .stream().collect(Collectors.toMap(ClassVo::getClassId, a -> a));
        //教学班学生
        List<ExcelStudent> excelStudent = studentMapper.getExcelStudent(teachingClassIds);
        Map<Long, List<ExcelStudent>> studentMap = excelStudent.stream().collect(Collectors.groupingBy
                (ExcelStudent::getTeachingClassId));

        //获取教师信息
        Map<Long, List<TeacherDto>> teachingClassToTeacher = teacherService.getTeacherByTeachingClassIds(teachingClassIds).stream()
                .collect(Collectors.groupingBy(TeacherDto::getTeachingClassId));
        //年级对应年级统一标识
        Map<String, String> globalGradeMap = yunBasicService.getGrade(taskInfo.getSchoolId())
                .stream().collect(Collectors.toMap(BaseGrade::getGradeID, BaseGrade::getGlobalGrade));

        List<List<String>> rows = new ArrayList<>();
        for (SyncTeachingClassDto teachingClass : courseTeachingClassList) {
            String courseName = "";
            String courseType = "";
            String teachingClassName = "";
            //暂且只有一个老师
            String teacherId = "";
            //上课对象字符串 C|2021级英语2班,2021级英语3班;S|stu036,stu037. 去掉已存行政班的学生
            String students = "";
            String globalGrade = globalGradeMap.size() > 0 ? new ArrayList<>(globalGradeMap.values()).get(0) : "U1";
            globalGrade = StrUtil.isBlank(teachingClass.getGradeId()) ? globalGrade : globalGradeMap.getOrDefault(teachingClass.getGradeId(), globalGrade);
            courseType = teachingClass.getCourseType();
            courseName = teachingClass.getCourseName();
            teachingClassName = teachingClass.getTeachingClassName();
            if (teachingClassToTeacher.containsKey(teachingClass.getTeachingClassId())) {
                //多教师版本
                teacherId = teachingClassToTeacher.getOrDefault(teachingClass.getTeachingClassId(), new ArrayList<>()).stream()
                        .map(TeacherDto::getBaseTeacherId).distinct().collect(Collectors.joining(","));
            }
            //学生字符串
            if (StrUtil.isNotBlank(teachingClass.getToClass())
                    && StrUtil.isEmpty(teachingClass.getUniqueShiftSign())
                    && StrUtil.isEmpty(teachingClass.getSplitClassUuid())) {
                //行政班id转化为行政班名称
                String[] classIds = teachingClass.getToClass().split(",");
                String className = Arrays.stream(classIds).map(a -> classMap.get(a).getClassName()).collect(Collectors.joining(","));
                if (StrUtil.isNotBlank(className)) {
                    students = "C|" + className;
                }
            }

            List<ExcelStudent> allStudents = studentMap.getOrDefault(teachingClass.getTeachingClassId(), new ArrayList<>());

            if (StrUtil.isNotBlank(students)) {
                List<String> classIds = Arrays.stream(teachingClass.getToClass().split(",")).distinct().collect(Collectors.toList());
                allStudents = allStudents.stream().filter(o -> !classIds.contains(o.getClassId()))
                        .collect(Collectors.toList());
            }
            String studentIds = allStudents.stream().map(ExcelStudent::getBaseStudentId).collect(Collectors.joining(","));

//            String studentIds = studentMap.getOrDefault(teachingClass.getTeachingClassId(), new ArrayList<>()).stream()
//                    .map(ExcelStudent::getBaseStudentId).collect(Collectors.joining(","));
            if (StrUtil.isNotBlank(studentIds)) {
                students = StrUtil.isNotBlank(students) ? students + ";" + "S|" + studentIds : "S|" + studentIds;
            }
            List<String> row = CollUtil.newArrayList(courseType, courseName, teachingClassName, teacherId, "覆盖", students, globalGrade);
            rows.add(row);
        }
        writer.write(rows, false);
        writer.close();
        return httpPath;
    }

    @Override
    public String allTeachingClassToExcel(Integer taskId, String importMode, Integer type) {
        String modelPath = GlobalConstant.MODEL_EXCEL_PATH + "【模板】教学班信息 (大学排课).xls";
        TaskInfo taskInfo = taskInfoService.getById(taskId);
        String storePath = "/" + taskInfo.getTermName() + "/syncTeachingClass" + UUID.randomUUID().toString() + ".xlsx";
        String targetPath = GlobalConstant.OUTPUT_EXCEL_PATH + storePath;

        FileUtil.copy(modelPath, targetPath, true);
        ExcelWriter writer = ExcelUtil.getWriter(targetPath);
        writer.setSheet(0);
        writer.passCurrentRow();
        writer.passCurrentRow();
        String httpPath = "/static/OutputExcel" + storePath;

        //课程教学班
        List<SyncTeachingClassDto> courseTeachingClassList = teachingClassMapper.syncCourseTeachingClassDto(taskId, type);
        //环节教学班
        if (type != null && type == 0) {
            List<SyncTeachingClassDto> segmentTeachingClassList = teachingClassMapper.syncSegmentTeachingClassDto(taskId);
            courseTeachingClassList.addAll(segmentTeachingClassList);
        }
        if (CollUtil.isEmpty(courseTeachingClassList)) {
            writer.close();
            return httpPath;
        }
        List<Long> teachingClassIds = courseTeachingClassList.stream().map(SyncTeachingClassDto::getTeachingClassId).collect(Collectors.toList());
        //获取行政班 及对应年级
        Map<String, ClassVo> classMap = studentMapper.getClassDto(taskId, null, null, null)
                .stream().collect(Collectors.toMap(ClassVo::getClassId, a -> a));
        //教学班学生
        List<ExcelStudent> excelStudent = studentMapper.getExcelStudent(teachingClassIds);
        Map<Long, List<ExcelStudent>> studentMap = excelStudent.stream().collect(Collectors.groupingBy
                (ExcelStudent::getTeachingClassId));

        //获取教师信息
        Map<Long, List<TeacherDto>> teachingClassToTeacher = teacherService.getTeacherByTeachingClassIds(teachingClassIds).stream()
                .collect(Collectors.groupingBy(TeacherDto::getTeachingClassId));
        //年级对应年级统一标识
        Map<String, String> globalGradeMap = yunBasicService.getGrade(taskInfo.getSchoolId())
                .stream().collect(Collectors.toMap(BaseGrade::getGradeID, BaseGrade::getGlobalGrade));

        List<List<String>> rows = new ArrayList<>();
        List<SyncTeachingClassVo> teachingClassVos = new ArrayList<>();
        for (SyncTeachingClassDto teachingClass : courseTeachingClassList) {
            if (StrUtil.isNotEmpty(teachingClass.getSplitTeacherUuid())) {
                if (SplitTeacherTeachingClass.contains(teachingClass.getSplitTeacherUuid())) {
                    if (teachingClassToTeacher.containsKey(teachingClass.getTeachingClassId())) {
                        //多教师版本
                        String teacherId = teachingClassToTeacher.getOrDefault(teachingClass.getTeachingClassId(), new ArrayList<>()).stream()
                                .map(TeacherDto::getBaseTeacherId).distinct().collect(Collectors.joining(","));

                        for (SyncTeachingClassVo o : teachingClassVos) {
                            if (StrUtil.isNotEmpty(o.getUuid())
                                    && o.getUuid().equals(teachingClass.getSplitTeacherUuid())) {
                                HashSet<String> ids = new HashSet<>();
                                ids.addAll(Arrays.asList(o.getTeacherId().split(",")));
                                ids.addAll(Arrays.asList(teacherId.split(",")));
                                o.setTeacherId(String.join(",", ids));
                            }
                        }
                    }
                    continue;
                } else {
                    SplitTeacherTeachingClass.put(teachingClass.getSplitTeacherUuid(), teachingClass.getTeachingClassName());

                }
            }

            String courseName = "";
            String courseType = "";
            String teachingClassName = "";
            //暂且只有一个老师
            String teacherId = "";
            //上课对象字符串 C|2021级英语2班,2021级英语3班;S|stu036,stu037. 去掉已存行政班的学生
            String students = "";
            String globalGrade = globalGradeMap.size() > 0 ? new ArrayList<>(globalGradeMap.values()).get(0) : "U1";
            globalGrade = StrUtil.isBlank(teachingClass.getGradeId()) ? globalGrade : globalGradeMap.getOrDefault(teachingClass.getGradeId(), globalGrade);
            courseType = teachingClass.getCourseType();
            courseName = teachingClass.getCourseName();
            teachingClassName = teachingClass.getTeachingClassName();
            if (teachingClassToTeacher.containsKey(teachingClass.getTeachingClassId())) {
                //多教师版本
                teacherId = teachingClassToTeacher.getOrDefault(teachingClass.getTeachingClassId(), new ArrayList<>()).stream()
                        .map(TeacherDto::getBaseTeacherId).distinct().collect(Collectors.joining(","));
            }
            //学生字符串
            if (StrUtil.isNotBlank(teachingClass.getToClass())
                    && StrUtil.isEmpty(teachingClass.getUniqueShiftSign())
                    && StrUtil.isEmpty(teachingClass.getSplitClassUuid())) {
                //行政班id转化为行政班名称
                String[] classIds = teachingClass.getToClass().split(",");
                String className = Arrays.stream(classIds).map(a -> classMap.get(a).getClassName()).collect(Collectors.joining(","));
                if (StrUtil.isNotBlank(className)) {
                    students = "C|" + className;
                }
            }

            List<ExcelStudent> allStudents = studentMap.getOrDefault(teachingClass.getTeachingClassId(), new ArrayList<>());

            if (StrUtil.isNotBlank(students)) {
                List<String> classIds = Arrays.stream(teachingClass.getToClass().split(",")).distinct().collect(Collectors.toList());
                allStudents = allStudents.stream().filter(o -> !classIds.contains(o.getClassId()))
                        .collect(Collectors.toList());
            }
            String studentIds = allStudents.stream().map(ExcelStudent::getBaseStudentId).collect(Collectors.joining(","));

            if (StrUtil.isNotBlank(studentIds)) {
                students = StrUtil.isNotBlank(students) ? students + ";" + "S|" + studentIds : "S|" + studentIds;
            }
            teachingClassVos.add(new SyncTeachingClassVo()
                    .setCourseType(courseType)
                    .setCourseName(courseName)
                    .setTeachingClassName(teachingClassName)
                    .setTeacherId(teacherId)
                    .setType("覆盖")
                    .setStudents(students)
                    .setGlobalGrade(globalGrade)
                    .setUuid(teachingClass.getSplitTeacherUuid())
            );
        }
        teachingClassVos.forEach(o -> {
            List<String> row = CollUtil.newArrayList(o.getCourseType(), o.getCourseName(), o.getTeachingClassName(), o.getTeacherId(), "覆盖", o.getStudents(), o.getGlobalGrade());
            rows.add(row);
        });
        writer.write(rows, false);
        writer.close();
        return httpPath;
    }

    @Override
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public List<TeachingClassWeek> setTeachingClassWeek(Integer taskId, List<TeachingClassWeek> teachingClassWeeks) {
        for (TeachingClassWeek item : teachingClassWeeks) {
            if (item.getNeedScheduleHour() == 0 && item.getWeekNum() != 0){
                item.setWeekNum(0);
            }
            if (item.getWeekNum() != 0 && item.getWeekNum() < item.getConnectNumber() * item.getConnectSection()) {
                throw new BizException("周学时不能少于连上节次乘以连上次数");
            }
            if (item.getWeekNum() == 0 && item.getNeedScheduleHour() != 0){
                throw new BizException("周学时为0时，实际排课学时必须为 0");
            }
        }
        List<Long> tcIds = teachingClassWeeks.stream().map(TeachingClassWeek::getTeachingClassId).collect(Collectors.toList());
        List<TeachingClassWeek> classWeekList = teachingClassWeekService.lambdaQuery().in(TeachingClassWeek::getTeachingClassId, tcIds).list();

        List<Long> collect = teachingClassWeeks.stream().filter(a -> ObjUtil.isNotEmpty(a.getRoomType())).map(TeachingClassWeek::getTeachingClassId).collect(Collectors.toList());
        if (CollUtil.isNotEmpty(collect)) {
            List<TeachingClassWeek> weeks = classWeekList.stream().filter(o -> collect.contains(o.getTeachingClassId())).collect(Collectors.toList());
//                    teachingClassWeekService.lambdaQuery().in(TeachingClassWeek::getTeachingClassId, collect).list();
            long count = weeks.stream().filter(a -> a.getRoomType() == null).count();
            if (count == 0) {
                this.lambdaUpdate().in(TeachingClass::getTeachingClassId, collect).set(TeachingClass::getIsEnable, 0).update();
            }
        }
        for (TeachingClassWeek teachingClassWeek : teachingClassWeeks) {
            TeachingClassWeek week = teachingClassWeekService.getById(teachingClassWeek.getId());
            if (week.getRoomType() == null || !week.getRoomType().equals(teachingClassWeek.getRoomType())) {
                teachingClassWeek.setRoomId(null);
                teachingClassWeek.setRoomName(null);
                teachingClassWeekMapper.updateForRoom(teachingClassWeek.getId());
            }
        }
        teachingClassWeekService.saveOrUpdateBatch(teachingClassWeeks);


        //修改课表
        if (scheduleService.lambdaQuery().in(Schedule::getTeachingClassId, tcIds).count() != 0) {
            TaskInfo taskInfo = taskInfoService.lambdaQuery().eq(TaskInfo::getTaskId, taskId).one();
            List<Long> weekIds = teachingClassWeeks.stream().map(TeachingClassWeek::getId).collect(Collectors.toList());
            Map<Long, TeachingClassWeek> originWeekMap = classWeekList.stream()
                    .filter(o -> weekIds.contains(o.getId()))
                    .collect(Collectors.toMap(TeachingClassWeek::getId, Function.identity()));

            for (TeachingClassWeek updateWeek : teachingClassWeeks) {
                if (originWeekMap.containsKey(updateWeek.getId())) {
                    TeachingClassWeek originWeek = originWeekMap.get(updateWeek.getId());
                    List<Long> scheduleIds = new ArrayList<>();
                    //没有修改周次需要删除课表
                    if (!updateWeek.getWeekNum().equals(originWeek.getWeekNum())
                            || !updateWeek.getConnectSection().equals(originWeek.getConnectSection())) {
                        teachingClassWeekService.lambdaUpdate()
                                .set(TeachingClassWeek::getScheduleState, ScheduleState.UNARRANGE.getCode())
                                .eq(TeachingClassWeek::getTeachingClassId, updateWeek.getTeachingClassId())
                                .eq(TeachingClassWeek::getHourType, updateWeek.getHourType())
                                .update();
                        scheduleService.lambdaUpdate()
                                .eq(Schedule::getTeachingClassId, updateWeek.getTeachingClassId())
                                .eq(Schedule::getHourType, updateWeek.getHourType())
                                .remove();
                        List<ScheduleConflictInfo> conflict = scheduleConflictInfoService.lambdaQuery()
                                .eq(ScheduleConflictInfo::getClashTeachingClassId, updateWeek.getTeachingClassId())
                                .eq(ScheduleConflictInfo::getHourType, updateWeek.getHourType())
                                .list();
                        scheduleIds.add(originWeek.getId());
                        if (CollUtil.isNotEmpty(conflict)) {
                            conflict.stream().map(ScheduleConflictInfo::getTeachingClassId)
                                    .distinct().forEach(o -> {
                                        //更新冲突表 排课状态
                                        arrangeCourseService.manualAdjustmentUpdate(taskInfo.getSchoolId(), taskInfo.getTerm(), taskId, null, o);
                                    });
                        }

                    }
                    if (CollUtil.isNotEmpty(scheduleIds)) {
                        List<GenerateTeachingClassUnitInput> unArrangeTeachingClassWeek = teachingClassMapper.getUnArrangeTeachingClassWeek(scheduleIds);
                        if (CollUtil.isNotEmpty(unArrangeTeachingClassWeek)){
                            scheduleService.generateTeachingClassUnit(taskId, unArrangeTeachingClassWeek);
                        }
                    }
                    //修改周次不删课表，更新冲突
                    if (!updateWeek.getWeek().equals(originWeek.getWeek())) {
                        scheduleService.lambdaUpdate()
                                .set(Schedule::getWeek, updateWeek.getWeek())
                                .eq(Schedule::getTeachingClassId, updateWeek.getTeachingClassId())
                                .eq(Schedule::getHourType, updateWeek.getHourType())
                                .update();
                        //更新冲突表 排课状态
                        arrangeCourseService.manualAdjustmentUpdate(taskInfo.getSchoolId(), taskInfo.getTerm(), taskId, null, updateWeek.getTeachingClassId());
                    }
                    if (updateWeek.getRoomId() != null) {
                        scheduleService.lambdaUpdate()
                                .eq(Schedule::getTeachingClassId, updateWeek.getTeachingClassId())
                                .eq(Schedule::getHourType, updateWeek.getHourType())
                                .isNull(Schedule::getTimeCode)
//                                .set(Schedule::getRoomType,updateWeek.getRoomType())
                                .set(Schedule::getRoomId, updateWeek.getRoomId())
                                .update();
                    }
//                    if (!updateWeek.getRoomType().equals(originWeek.getRoomType())
//                            || !updateWeek.getRoomId().equals(originWeek.getRoomId())) {
//                        scheduleService.lambdaUpdate()
//                                .eq(Schedule::getTeachingClassId, updateWeek.getTeachingClassId())
//                                .eq(Schedule::getHourType, updateWeek.getHourType())
//                                .isNull(Schedule::getTimeCode)
////                                .set(Schedule::getRoomType,updateWeek.getRoomType())
//                                .set(Schedule::getRoomId, updateWeek.getRoomId())
//                                .update();
//                    }

                }
            }
        }


        return teachingClassWeeks;
    }


}
